//#include <iostream>
//using namespace std;
//
//const int N = 1e6 + 10;
//
//int n,mai = 1,mii;
//int a[N],f[N];
//
//int main(){
//	cin >> n;
//	for(int i = 1;i <= n;i++){
//		cin >> a[i];
//		f[i] = f[i - 1] + a[i];
//		if(f[i] > f[mai]) mai = i;
//		if(f[i] < f[mii]) mii = i;
//	}
//	cout << f[mai] - f[mii] << endl;
//	cout << mai << " " << mii;
//	return 0;
//}

#include <iostream>
using namespace std;

const int N = 2e5 + 10;

int n;
long long int f[N],minf = 0,suma = -1e20;

int main(){
	cin >> n;
	for(int i = 1;i <= n;i++){
		int x;
		cin >> x;
		f[i] = f[i - 1] + x;
		suma = max(suma,f[i] - minf);
		minf = min(minf,f[i]);
	}
	cout << suma << endl;
	return 0;
}
